﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZombieMonkeys.Vibria.Logic
{
    public class PuzzleChecker
    {
        private static PuzzleChecker instance;

        public static PuzzleChecker Instance
        {
            get { return instance; }
            
        }

        public PuzzleChecker GetPuzzleChecker()
        { 
            if (instance == null)
            {
                instance = new PuzzleChecker();
            }
            return instance;
        }

        public bool Check(Puzzle puzzleToSolve)
        {
            Puzzle puzzleBeingChecked = puzzleToSolve;

            bool groupsCheck = false;
            bool rowsCheck = false;
            bool colsCheck = false;

            bool puzzleSolved = false;

            //if groupsCheck, set true and continue to rows
            checkGroups(puzzleBeingChecked);

            if (groupsCheck)
            {
                //if rowsCheck, set true and continue to cols
                checkRows(puzzleBeingChecked);
                if (rowsCheck)
                {
                    //if colsCheck, set true and return Puzzle solved
                    checkColumns(puzzleBeingChecked);
                    if (colsCheck)
                    {
                        puzzleSolved = true;
                    }
                }
            }
            else
            {
                puzzleSolved = false;
            }
            return puzzleSolved;
        }

        //if we want to do real time checking of the puzzle then we should have an Update like this
        public void Update(Puzzle puzzle)
        { 
            //i suppose we will do the entire checking logic in this  call, we may have to multithread this
            //if that is the case I might need some help on that, I have very little experience with multithreading
        }

        private void checkGroups(Puzzle puzzle)
        { 
            //check the groups
            for (int i = 0; i < puzzle.Grid.SquareList.Count; i++)
            {
                
            }
        }

        private void checkRows(Puzzle puzzle)
        {
            for (int i = 0; i < puzzle.Grid.SquareList.Count; i++)
            {
                
            }
        }

        private void checkColumns(Puzzle puzzle)
        {
            for (int i = 0; i < puzzle.Grid.SquareList.Count; i++)
            {
                
            }
        }
        
    }
}
